/**
 * zmn 花名册模块-服务分类-产品分类关联
 * @author tanghongjun
 * @since 2020-08-25 14:35:13
 */
layui.define(['index', 'form', 'table', 'laypage', 'layedit', 'laydate', "zmnSelect"], function (exports) {
    var $ = layui.$;
    var form = layui.form;
    var layer = layui.layer;
    var table = layui.table;
    var laypage = layui.laypage;
    var layedit = layui.layedit;
    var laydate = layui.laydate;
    var zmnSelect = layui.zmnSelect;
    form.render(null, "zmn-form");

    laydate.render({elem: "#perTime", type: "date"});

    // 提交
    form.on('submit(zmn-form-submit)', function (obj) {
        var data = obj.field;
        if (zmnUtil.isEmptyNull(data.perProductGroupcId)) {
            data.perProductGroupcName = "";
        } else {
            data.perProductGroupcName = $("#perProductGroupcId option:selected").text();
        }


        if (zmnUtil.isEmptyNull(data.perProductGroupfId)) {
            data.perProductGroupfName = "";
        } else {
            data.perProductGroupfName = $("#perProductGroupfId option:selected").text();
        }


        if (zmnUtil.isEmptyNull(data.perProductGroupbId)) {
            data.perProductGroupbName = "";
        } else {
            data.perProductGroupbName = $("#perProductGroupbId option:selected").text();
        }

        var url = "/serv/categ/ass/updateBizTypeGroup.action";

        $.ajax({
            async: false,
            type: "POST", url: url,
            contentType: "application/json", dataType: "json", data: JSON.stringify(data),
            success: function (result) {
                if (result.status == 200) {
                    parent.reload(result.message);
                    cancel();
                } else {
                    layui.layer.msg(result.message, {"icon": 2});
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
            }
        })
        return false;
    });

    function contrastData(val1) {
        let time = new Date(val1).getTime();
        let now = new Date().getTime();

        if (time < now) {
            return true;
        }
        return false;
    }

    //对外暴露的接口
    exports('plat_servAssCategory_detail', {});
});

// 取消
function cancel() {
    let index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
    parent.layer.close(index);
}